package com.example.zzm.yuejian03.Activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.zzm.yuejian03.Bean.MyBean;
import com.example.zzm.yuejian03.Bean.collectBean;
import com.example.zzm.yuejian03.Listener.MyListener;
import com.example.zzm.yuejian03.Listener.TListener;
import com.example.zzm.yuejian03.Model.MyModel;
import com.example.zzm.yuejian03.Model.updatenameModel;
import com.example.zzm.yuejian03.R;

public class updetanameActivity extends AppCompatActivity {

    private Button button27;
    private TextView textView11;
    private EditText editText8;
    private int uid;
    private SharedPreferences sp;

    public void  onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.updatename);
        initView();
        initEvent();
        sp = getSharedPreferences("userInfo", MODE_PRIVATE);
        uid = sp.getInt("user_id",1);
        MyModel myModel = new MyModel();
        myModel.getMys(uid,userinfo);

    }
    TListener<MyBean> userinfo = new TListener<MyBean>() {
        @Override
        public void onResponse(MyBean user) {
            editText8.setText(user.getReal_name());
        }

        @Override
        public void onFail(String msg) {

        }
    };

    private void initEvent() {
        textView11.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        button27.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String realName = editText8.getText().toString();
                updatenameModel myModel = new updatenameModel();
                myModel.getupdatename(uid,realName,listener);
                finish();
            }
        });
    }

    private void initView() {
        textView11=(TextView)findViewById(R.id.textView11);
        button27 = (Button)findViewById(R.id.button27);
        editText8 = (EditText)findViewById(R.id.editText8);
    }

    TListener<collectBean> listener = new TListener<collectBean>() {
        @Override
        public void onResponse(collectBean collectBean) {
            Toast.makeText(updetanameActivity.this,"修改名称成功", Toast.LENGTH_SHORT).show();
//            Intent intent = new Intent(updetanameActivity.this,LoginActivity.class);
//            startActivity(intent);
              finish();
        }

        @Override
        public void onFail(String msg) {

        }
    };
}
